package edu.rit.drh4818.fire.data;


/**
 * A mistake, which looks cool.
 * 
 * @author Darren Headrick
 *
 */
public class WTFData extends EmitterVolume
{
	public static String NAME = "WTF";
	private static final int DIMENSION = 50;
	private int count = 0;
	
	public WTFData()
	{
		super( DIMENSION, true, NAME );
	}
	
	/*
	 * (non-Javadoc)
	 * @see edu.rit.drh4818.volume.renderer.VolData#update()
	 */
	public void update() 
	{
		if( volData == null ) return;
		
		super.update();
		
		if( count++ >  15 ) { count = 0; setup(); }
		
		for(int z = 0; z < DIMENSION; z++ )
		for(int y = DIMENSION-1; y > 1 ; y--)
	    for(int x = 0; x < DIMENSION - 1; x++)
	    {
	    	volData[x][y][z] = (short)(
  	          (((volData[(x - 1 + DIMENSION) % DIMENSION][(y - 1) % DIMENSION][z]
                + volData[x % DIMENSION][(y - 1) % DIMENSION][z]
                + volData[(x + 1) % DIMENSION][(y - 1) % DIMENSION][z]
                + volData[x % DIMENSION][(y - 2 + DIMENSION) % DIMENSION][z]
                + volData[x][(y - 1) % DIMENSION][(z - 1 + DIMENSION) % DIMENSION]
                + volData[x][(y - 1) % DIMENSION][(z + 1) % DIMENSION]
                )* 64) / 257));
	    }

		generateTexture();
	}

	/**
	 * Change the direction of the dataset.
	 */
	public short get( int x, int y, int z )
    {
		if( volData == null ) return 0;

		if( volData[x][y][z] > 255 ) return 0;
    	return (short)(255 - volData[x][y][z]);
    }
}
